package com.ms.service.module.account.db;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.Type;

import com.xpec.c4.db.model.basic.BasicGameModel;

/**
 * 账户实体类
 * @author zhongzhengkai
 *
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "accounts", uniqueConstraints = { @UniqueConstraint(columnNames = { "accountId" }) })
@org.hibernate.annotations.Table(
	appliesTo = "accounts", indexes =
	{
			@org.hibernate.annotations.Index(name = "IDX_LASTLOCKPLAYER", columnNames = { "lastLockPlayerGUID"}),
			@org.hibernate.annotations.Index(name = "IDX_DEVICE_ID", columnNames = { "deviceID"}),
			@org.hibernate.annotations.Index(name = "IDX_COOP_ACCOUNT_ID", columnNames = { "cooperatorAccountId"}),
	}
)
public class AccountModel extends BasicGameModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8479123747212874276L;

	/**
	 * 帐户
	 */
	private String accountId;
	
	/**
	 * 立即玩編號
	 * <ul>
	 * <li>0 普通帳號
	 * <li>1-9999 立即玩帳號
	 * </ul>
	 */
	private int trialNumber;
	
	/**
	 * 角色列表
	 */
	private ArrayList<String> players = new ArrayList<String>();
	
	/**
	 * 線金
	 */
	private long cash;
	
	/**
	 * 紅利
	 */
	private BigDecimal bonus;

	/**
	 * 銀行密碼
	 */
	private String bankPassword;
	
	/**
	 * 營運商accountID
	 */
	private String cooperatorAccountId;
	
	/**
	 * 注册账号时间<br>
	 * 
	 * @author SuYingLong
	 * @version 2013-1-29 下午02:54:57
	 */
	private Calendar time;
	
	/**
	 * gm權利 (不受人數影響可登入)
	 */
	private int gmPower;
	
	/**
	 * 營運商平台ID (日版需要)
	 */
	private int portalId;
	
	/**
	 * 營運商平台使用者ID
	 */
	private String portalAccountId;
	

	/**
	 * 已創角數目
	 */
	private int createdPlayerCount;
	
	/**
	 * 角色Guid及對應編號
	 */
	private Map<String, Integer> playerSerialNumMap = new HashMap<String, Integer>();

	/**
	 * 上線的邀請碼
	 */
	private String uplineCode;

	/**
	 * 活動代碼，透過營運商特定網址登入時會帶入的代碼
	 */
	private String cooperatorEventCode;

	/**
	 * 綁定手機號碼
	 */
	private String bindPhone;

	/**
	 * 綁定信箱
	 */
	private String bindMail;
	
	/*
	 * 認證時間 
	 */
	private Calendar registerTime;
	
	/**
	 * 是否已經有首次轉點角色 
	 */
	private boolean haveFirstStoreCharacter;
	
	/**
	 * 創建帳號的平台
	 */
	private String registeredPlatform;
	
	/**
	 * 被禁止登入的時間
	 */
	private long loginBanTime;
	
	/**
	 * 被禁止登入的原因
	 */
	private String banLoginTimeReson;
	
	/**
	 * 上次鎖定的角色GUID
	 */
	private String lastLockPlayerGUID;
	
	/**
	 * deviceToken,有效時間(秒)
	 */
	private String deviceToken;
	
	/**
	 * 邀請碼錯誤次數
	 */
	private int inviteCodeErrorCount;
	
	/**
	 * 邀請碼錯誤次數到達上限，解鎖時間
	 */
	private Date inviteCodeUnlockTime;
	
	/**
	 * 該帳號對應的deviceID
	 */
	private String deviceID;
	
	/**
	 * 營運商 id
	 */
	private String venderId;
	
	/**
	 * 子營運商 id
	 */
	private String subVenderId;

	@Column(columnDefinition="VARCHAR(255) BINARY CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL")
	public String getAccountId() {
		return accountId;
	}

	public void setAccountId(String accountId) {
		this.accountId = accountId;
	}

	/*public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
*/
	@Type(type = "com.xpec.c4.db.usertype.ArrayListStringToString")
	public ArrayList<String> getPlayers() {
		return players;
	}

	public void setPlayers(ArrayList<String> players) {
		this.players = players;
	}
	public String getCooperatorAccountId() {
		return cooperatorAccountId;
	}

	public void setCooperatorAccountId(String cooperatorAccountID) {
		this.cooperatorAccountId = cooperatorAccountID;
	}

	public Calendar getTime() {
		return time;
	}

	public void setTime(Calendar time) {
		this.time = time;
	}

	public int getGmPower()
    {
	    return gmPower;
    }

	public void setGmPower(int gmPower)
    {
	    this.gmPower = gmPower;
    }

	@Column(name = "portalId", nullable = false, columnDefinition = "int(11) default 0")
	@Index(name = "portalId")
	public int getPortalId()
    {
	    return portalId;
    }

	public void setPortalId(int portalId)
    {
	    this.portalId = portalId;
    }

	@Index(name = "portalAccountId")
	public String getPortalAccountId()
    {
	    return portalAccountId;
    }

	public void setPortalAccountId(String portalAccountId)
    {
	    this.portalAccountId = portalAccountId;
    }

	@Column(nullable = false, columnDefinition = "int(11) default 0")
	public int getCreatedPlayerCount()
    {
	    return createdPlayerCount;
    }

	public void setCreatedPlayerCount(int createdPlayerCount)
    {
	    this.createdPlayerCount = createdPlayerCount;
    }

	@Type(type = "com.xpec.c4.db.usertype.MapStringIntegerToString")
	public Map<String, Integer> getPlayerSerialNumMap()
    {
	    return playerSerialNumMap;
    }

	public void setPlayerSerialNumMap(Map<String, Integer> playerSerialNumMap)
    {
	    this.playerSerialNumMap = playerSerialNumMap;
    }

	public int getTrialNumber() {
		return trialNumber;
	}

	public void setTrialNumber(int trialNumber) {
		this.trialNumber = trialNumber;
	}

	public long getCash() {
		return cash;
	}

	public void setCash(long cash) {
		this.cash = cash;
	}

	@Column(precision = 19, scale = 2 , columnDefinition="DECIMAL(19,2) default 0.0")
	public BigDecimal getBonus() {
		return bonus;
	}

	public void setBonus(BigDecimal bonus) {
		this.bonus = bonus;
	}
	
	public String getBankPassword() {
		return bankPassword;
	}

	public void setBankPassword(String bankPassword) {
		this.bankPassword = bankPassword;
	}

	public String getUplineCode() {
		return uplineCode;
	}

	public void setUplineCode(String uplineCode) {
		this.uplineCode = uplineCode;
	}

	public String getCooperatorEventCode() {
		return cooperatorEventCode;
	}

	public void setCooperatorEventCode(String cooperatorEventCode) {
		this.cooperatorEventCode = cooperatorEventCode;
	}

	public String getBindPhone() {
		return bindPhone;
	}

	public void setBindPhone(String bindPhone) {
		this.bindPhone = bindPhone;
	}

	public String getBindMail() {
		return bindMail;
	}

	public void setBindMail(String bindMail) {
		this.bindMail = bindMail;
	}

	public Calendar getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Calendar registerTime) {
		this.registerTime = registerTime;
	}
	
	@Column(nullable = false, columnDefinition = "BOOLEAN DEFAULT false")
	public boolean isHaveFirstStoreCharacter() {
		return haveFirstStoreCharacter;
	}

	public void setHaveFirstStoreCharacter(boolean haveFirstStoreCharacter) {
		this.haveFirstStoreCharacter = haveFirstStoreCharacter;
	}
	
	public long getLoginBanTime() {
		return loginBanTime;
	}

	public void setLoginBanTime(long loginBanTime) {
		this.loginBanTime = loginBanTime;
	}

	@Column(columnDefinition="VARCHAR(50) BINARY CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL")
	public String getBanLoginTimeReson() {
		return banLoginTimeReson;
	}

	public void setBanLoginTimeReson(String banLoginTimeReson) {
		this.banLoginTimeReson = banLoginTimeReson;
	}

	public String getRegisteredPlatform() {
		return registeredPlatform;
	}

	public void setRegisteredPlatform(String registeredPlatform) {
		this.registeredPlatform = registeredPlatform;
	}

	public String getLastLockPlayerGUID() {
		return lastLockPlayerGUID;
	}

	public void setLastLockPlayerGUID(String lastLockPlayerGUID) {
		this.lastLockPlayerGUID = lastLockPlayerGUID;
	}

	public String getDeviceToken() {
		return deviceToken;
	}

	public void setDeviceToken(String deviceToken) {
		this.deviceToken = deviceToken;
	}
	
	public int getInviteCodeErrorCount() {
		return inviteCodeErrorCount;
	}

	public void setInviteCodeErrorCount(int inviteCodeErrorCount) {
		this.inviteCodeErrorCount = inviteCodeErrorCount;
	}

	public Date getInviteCodeUnlockTime() {
		return inviteCodeUnlockTime;
	}

	public void setInviteCodeUnlockTime(Date inviteCodeUnlockTime) {
		this.inviteCodeUnlockTime = inviteCodeUnlockTime;
	}

	public String getDeviceID() {
		return deviceID;
	}

	public void setDeviceID(String deviceID) {
		this.deviceID = deviceID;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Column(columnDefinition="VARCHAR(50) NOT NULL default 'TONWA'")
	public String getVenderId() {
		return venderId;
	}

	public void setVenderId(String venderId) {
		this.venderId = venderId;
	}

	@Column(columnDefinition="VARCHAR(50) NOT NULL default 'TONWA'")
	public String getSubVenderId() {
		return subVenderId;
	}

	public void setSubVenderId(String subVenderId) {
		this.subVenderId = subVenderId;
	}
}
